package com.yeban.javase.day07.test3_stringbuilder;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/10/15
 */
/**
 * 1.使用System类获取当前系统的毫秒值
 * 统计代码的执行时间，String拼接+  、StringBuilder拼接
 */
public class Test01 {
    public static void main(String[] args) {

        long startTime1 = System.currentTimeMillis();
        String str1 = "abc";
        for (int i = 0; i < 50000; i++) {
            str1 += "i";
        }
        long endTime1 = System.currentTimeMillis();

        long startTime2 = System.currentTimeMillis();
        StringBuilder str2 = new StringBuilder("abc");
        for (int i = 0; i < 50000; i++) {
            str2.append("i");
        }
        long endTime2 = System.currentTimeMillis();

        long result1 = Math.abs(endTime1 - startTime1);
        long result2 = Math.abs(endTime2 - startTime2);
        System.out.println("String 拼接+的运行时间为：" + result1 + "毫秒");
        System.out.println("StringBuilder 拼接+的运行时间为：" + result2 + "毫秒");

    }
}
